<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>首页品牌管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			checkSize();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				rules:{          
					remarks:{remarkCheck:true}
	            },
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			jQuery.validator.addMethod("remarkCheck", function(value,  
	                element, param) { 
				if(value.length>100){
					return false;
				} else{
					return true;
	            }
	        }, $.validator.format("字数超限"));
			$("#remarks").keyup(function(){
				checkSize();
			})
			
			
			$('.upload_img').click(function(){
				$(this).prev('input').click();
			})
		});
		
		function checkSize(){
			var curLength=$("#remarks").val().length;
			if(curLength>100){
				$("#textLength").css("color","red");
				$("#textLength").text(curLength+"/100");
			}else{
				$("#textLength").css("color","");
				$("#textLength").text(curLength+"/100");
			}
		}
		
		function getFullPath(obj) {  
		      if (obj) {  
		          //Internet Explorer   
		          if (window.navigator.userAgent.indexOf("MSIE") >= 1) {  
		              obj.select();  
		              return document.selection.createRange().text;  
		          }   
		          //Firefox  
		          if (window.navigator.userAgent.indexOf("Firefox") >= 1) {  
		              if (obj.files) {  
		                  return window.URL.createObjectURL(obj.files[0]);
		              }  
		              return obj.value;  
		          }   
		    
		          //兼容chrome、火狐等，HTML5获取路径         
		          if (typeof FileReader != "undefined") {  
		              var reader = new FileReader();  
		              reader.onload = function(e) {  
		                  //document.getElementById("pic").src = e.target.result + ""; 
		                  $(obj).next('.upload_img').find('img').attr('src',e.target.result);
		              }  
		              reader.readAsDataURL(obj.files[0]);  
		          } else if (browserVersion.indexOf("SAFARI") > -1) {  
		              
		          }  
		    
		      }   
		  }  
		    
		  function showPic(obj) {  
		      var fullPath = getFullPath(obj);  
		      if (fullPath) {  
		           $(obj).next('.upload_img').find('img').attr('src',fullPath);
		      }  
		      
		  }
		  
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/carBrand/">首页品牌列表</a></li>
		<li class="active"><a href="${ctx}/sys/carBrand/form?id=${carBrand.id}">首页品牌<shiro:hasPermission name="sys:carBrand:edit">${not empty carBrand.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="sys:carBrand:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="carBrand" action="${ctx}/sys/carBrand/save" method="post" class="form-horizontal" enctype="multipart/form-data">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>	
		
		<div class="control-group">
			<label class="control-label">品牌：</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="255" readonly="true" class="input-xlarge "/>
			</div>
		</div>	
		<label class="control-label">图片：</label>
		<div class="control-group">
		    <input type="file" name='images' onchange="showPic(this)" style='display:none' />
		    
			  <div class="upload_img" style='cursor:pointer;width:220px;height:100px;display:inline-block;'>				   
			 	 <img class='change_photo' src="${carBrand.img}" alt="" style="width:220px;height:100px; margin-left:20px;" />				     
			  </div> 
		</div>
		 <div class="control-group">
			<label class="control-label">链接：</label>
			<div class="controls">
				<form:input path="url" htmlEscape="false" maxlength="255" class="input-xlarge required url"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">备注：</label>
			<div class="controls">
			    <span id="textLength" style="margin-top: 74px;position: absolute;line-height: 1; margin-left: 475px;color: red;">0/100</span>
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="255" class="input-xxlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="sys:carBrand:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>